<!-- 见证任务主页 -->
<template>
  <div>
    <!-- <TabMenu :tabList="tabList" />
    <router-view /> -->
    <el-tabs v-model="activeName" @tab-click="handleClick">
      <el-tab-pane v-for="(item, index) in activeNameList" :key="index" :label="item.label" :name="item.value">
        <div class="layout-header layout-search">
          <el-form :inline="true" :model="searchForm">
            <el-form-item label="交易方式">
              <el-select
                v-model="searchForm.tenderMode"
                class="ui-w180"
                option-max-width="180px"
                placeholder="请选择"
                clearable
                @change="handleSearchFn()"
              >
                <!-- <el-option key label="全部" value></el-option> -->
                <el-option
                  v-for="(item, key) in tenderModeOptionsObj"
                  :key="key"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
            <el-form-item label="见证环节">
              <el-select
                v-model="searchForm.zsType"
                class="ui-w180"
                option-max-width="180px"
                placeholder="请选择"
                clearable
                @change="handleSearchFn()"
              >
                <!-- <el-option key label="全部" value></el-option> -->
                <el-option v-for="item in zsModeOptionsObj" :key="item.value" :label="item.label" :value="item.value" />
              </el-select>
            </el-form-item>
          </el-form>
        </div>
        <div class="layout-body">
          <task-table
            :table-data="tableTaskList"
            :table-loading="tableLoading"
            :page-size="pageObj.pageSize"
            :current-page="pageObj.currentPage"
            :selection="false"
            :witness-link-code="'haveWitnessed'"
          />
        </div>
        <div class="layout-footer">
          <pagination
            v-if="pageObj.total > pageObj.pageSizes[0]"
            :total="pageObj.total"
            :page.sync="pageObj.currentPage"
            :limit.sync="pageObj.pageSize"
            :page-sizes="pageObj.pageSizes"
            @pagination="witnessRecordDistributeListFn()"
          />
        </div>
      </el-tab-pane>
    </el-tabs>
  </div>
</template>
<script>
  // 这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
  // import TabMenu from "../../../../components/layout/components/tabMenu.vue";
  // import engineeringBuild from "./warn/engineeringBuild.vue";
  import TaskTable from "./Table";
  import { warnModuleInit, newWarnList } from "../../../../api/api";
  export default {
    // 引入组件
    components: {
      // engineeringBuild,
      TaskTable
    },
    props: {},
    data() {
      // 这里存放数据
      return {
        tableLoading: false,
        activeName: "GCJS",
        activeNameList: [],
        warningLevelList: [],
        tenderModeOptionsObj: [],
        zsModeOptionsObj: [],
        tableTaskList: [],
        TypeNameList: {},
        searchForm: {
          tenderMode: "",
          zsType: ""
        },
        pageObj: {
          total: 0,
          currentPage: 1,
          pageSize: 10,
          pageSizes: [10, 20, 30]
        },
        tabList: [
          // {
          //   path: "/warningRule/engineeringBuild",
          //   title: "工程建设",
          // },
          // {
          //   path: "/WitnessTask/ToWitness",
          //   title: "待见证",
          // },
          // {
          //   path: "/WitnessTask/HaveWitnessed",
          //   title: "已完成",
          // },
        ]
      };
    },
    // 监听属性 类似于data概念
    computed: {},
    // 监控data中的数据变化
    watch: {},
    // 生命周期 - 创建完成（可以访问当前this实例）
    created() {
      this.warnModuleInitFn();
      this.newWarnListFn(this.activeName);
    },
    // 生命周期 - 挂载完成（可以访问DOM元素）
    mounted() {},
    // 生命周期 - 销毁之前
    beforeDestroy() {},
    // 生命周期 - 销毁完成
    destroyed() {},
    // 如果页面有keep-alive缓存功能，这个函数会触发
    activated() {},
    // 方法集合
    methods: {
      async warnModuleInitFn() {
        try {
          const res = await warnModuleInit({ moduleName: "WARNING_RULE" });
          if (res.success) {
            this.activeNameList = res.data.industryTypeAndTenderMode;
            this.warningLevelList = res.data.warningLevel;
            // this.warningLevelList = res.data.warningLevel;
            this.activeNameList = res.data.industryTypeAndTenderMode;
            this.activeNameList.map((item) => {
              if (this.activeName == item.value) {
                this.tenderModeOptionsObj = item.children;
              }
            });
          } else {
            this.$message({
              type: "error",
              message: res.message || "获取数据失败，请稍后再试",
              single: true
            });
          }
        } catch (error) {
          console.log(error);
        }
      },
      async newWarnListFn(activeName) {
        this.tableLoading = true;
        const params = {
          industryType: activeName,
          tenderMode: this.searchForm.tenderMode,
          witnessLinkCode: this.searchForm.zsType,
          currentPage: this.pageObj.currentPage,
          pageSize: this.pageObj.pageSize
        };
        try {
          const res = await newWarnList(params);
          this.tableTaskList = res.data;
          this.tableLoading = false;
        } catch (error) {
          console.log(error);
        }
      },
      handleClick(e) {
        this.searchForm = {
          tenderMode: "",
          zsType: ""
        };
        this.zsModeOptionsObj = [];
        this.activeName = e.name;
        this.tenderModeOptionsObj = [];
        if (this.activeName === "GCJS") {
          this.newWarnListFn(this.activeName);
          this.warnModuleInitFn();
        }
        if (this.activeName === "ZFCG") {
          this.newWarnListFn(this.activeName);
          this.warnModuleInitFn();
        }
      },
      handleSearchFn(e) {
        this.activeNameList.map((item) => {
          if (this.activeName == item.value) {
            item.children.map((jtem) => {
              if (this.searchForm.tenderMode === jtem.value) {
                this.zsModeOptionsObj = jtem.children;
              }
            });
          }
        });
        this.newWarnListFn(this.activeName);
      }
    }
  };
</script>
<style lang="scss" scoped></style>
